package com.sky.controller.admin;

import com.github.pagehelper.Constant;
import com.sky.constant.RedisConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Tags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/admin/shop")
@RestController("adminShopController")
@Slf4j
@Api(tags="管理端店铺相关")
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    @ApiOperation("店铺状态设置")
    public Result<String> setShopStatus(@PathVariable Integer status){
        log.info("店铺状态设置{}",status);
        redisTemplate.opsForValue().set(RedisConstant.SHOP_STATUS_KEY,status);
        return Result.success();
    }
    @ApiOperation("管理端营业状态")
    @GetMapping("/status")
    public Result<Integer> getShopStatus( ){
        log.info("管理端营业状态");
        Integer status =(Integer) redisTemplate.opsForValue().get(RedisConstant.SHOP_STATUS_KEY);
        if (status==null){
            status=0;
        }
        return Result.success(status);
    }
}
